﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using zeus.Core;
using zeus.Core.RepositoryInterfaces;
using SharpArch.Data.NHibernate;
using NHibernate;
using NHibernate.Transform;
using NHibernate.Criterion;

namespace zeus.Data
{
    public class PoligonoRepository : Repository<Poligono>, IPoligonoRepository
    {
        public IList<Poligono> GetPoligonoByCliente(int ClienteID)
        {
            return Session.CreateSQLQuery("select p.* from poligono as p inner join unidad as u on p.und_id = u.und_id where u.cli_id = :cli_id and p.pol_tipo = 1")
                    .AddEntity(typeof(Poligono))
                    .SetInt32("cli_id", ClienteID)
                    .List<Poligono>();
        }

        public IList<Poligono> GetRutaByCliente(int ClienteID)
        {
            return Session.CreateSQLQuery("select p.* from poligono as p inner join unidad as u on p.und_id = u.und_id where u.cli_id = :cli_id and p.pol_tipo = 2")
                    .AddEntity(typeof(Poligono))
                    .SetInt32("cli_id", ClienteID)
                    .List<Poligono>();
        }

        public void DeleteDetalles(int PoligonoID)
        {
            Session.Delete("from PoligonoDetalle d where d.Poligono.Id = " + PoligonoID.ToString());
            Session.Flush();
        }
    }
}
